package FileManager;

import java.util.Arrays;

import DiskManager.Disk;
import javafx.scene.control.TreeItem;
import javafx.scene.layout.VBox;

public abstract class SimulateContent {
	char[] name = new char[6];
	char[] ExtendName = new char[2];
	char[] attribute = new char[1];
	char[] startnum  = new char[3];
    char[] size = new char[4];
	    private TreeItem<String> treeItem = new TreeItem<String>() ;
	    private VBox  vBox;  
	    private String AbsolutePath;
        public VBox getvBox() {
			return vBox;
		}

		public void setvBox(VBox vBox) {
			this.vBox = vBox;
		}

		public TreeItem<String> getTreeItem() {
			return treeItem;
		}

		public void setTreeItem(TreeItem<String> treeItem) {
			this.treeItem = treeItem;
			
		}

	
        public String getName() {
        	String Name = new String(this.name);
			return Name;
		}
		
		public String getExtendName() {
			String ExtendName = new String(this.ExtendName);
			return ExtendName;
		}
		
		public String getAttribute() {
			String Attribute = new String(this.attribute);
			return Attribute;
		}
		
		public int getStartnum() {
			String startnum = new String(this.startnum);
			int Startnum = Integer.valueOf(startnum);
			return Startnum;
		}
		public int getSize() {
			String Size = new String(this.size);
			int size = Integer.valueOf(Size);
			return size;
		}
		 public void setExtendName(String newName) {
		    	char[] string = newName.replaceAll(" ", "").toCharArray();
		    	this.ExtendName = string;
		    }
		 public void setattribute(String newattribute) {
		    	char[] string = newattribute.replaceAll(" ", "").toCharArray();
		    	this.attribute = string;
		    }
		    
		 public void setstranum(int newstarnum) {
		    	char[] string = Integer.toString(newstarnum).replaceAll(" ", "").toCharArray();
		    	this.startnum = string;
		    }

		 public void setName(String newName) {
		    	char[] string = newName.replaceAll(" ", "").toCharArray();
		    	this.name = string;
		    }
	   public void setSize(int newSize) {
		    	char[] string = Integer.toString(newSize).replaceAll(" ", "").toCharArray();
		    	this.size = string;
		    }
		public String getAbsolute()
		{
			if(this.getName().equals("MyCMT"))
				AbsolutePath = "";
			else {
				if(this.father.getName().equals("MyCMT"))
					AbsolutePath = "/MyCMT";
				else
					AbsolutePath = this.father.getAbsolute()+"/"+this.getName();
			}
			
			return AbsolutePath;
		}
		public SimulationDirectory getFather() {
			return father;
		}
		public void setFather(SimulationDirectory father) {
			
			this.father = father;
			this.father.addChildren(this);
		}
		
        SimulationDirectory father;
		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + Arrays.hashCode(ExtendName);
			result = prime * result + Arrays.hashCode(name);
			return result;
		}
		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			SimulateContent other = (SimulateContent) obj;
			
			if (!Arrays.equals(ExtendName, other.ExtendName))
				return false;
			if (!Arrays.equals(name, other.name))
				return false;
			return true;
		}
		
		
		public char judgeDirectory(int startnum) {
			if(startnum==2) {
				switch(this.father.getName()) {
				case("C"):return 'C';
				case("D"):return 'D';
				case("E"):return 'E';
				case("F"):return 'F';
				}
			}
			if(startnum>=3&&startnum<=62)return 'C';
			if(startnum>=63&&startnum<=122)return 'D';
			if(startnum>=123&&startnum<=182)return 'E';
			if(startnum>=183&&startnum<=242)return 'F';
			System.out.println("judgeDirectory_ERROR");
			return 'N';
		}
		
       public void clear(Disk disk)    //清空自身的操作
       {
    	  int i = this.getStartnum();
    	  int j =disk.getFAT()[i];
    	  while(i!=-1) {
    		  disk.getDiskBit()[i].clear();
    		  j = disk.getFAT()[i];
    		  disk.setFAT(i, 0);
    		  i=j;
    	  }
       }
       
       public void changeSize(SimulateContent current,int num) {
    	   if(current.getStartnum()!=1) {
    		   current.setSize(current.getSize()+num);
    		   changeSize(current.father, num);
    	   }
    	   return;
       }
}
